<?php

	/**
	 * @see Bike_Js_Base
	 */
	require_once 'Bike/Js/Base.php';
	
	/**
	 * @see Bike_Js_Interface_JsonUnavailable
	 */
	require_once 'Bike/Js/Interface/JsonUnavailable.php';
	
	
	class Bike_Js_Container extends Bike_Js_Base implements Bike_Js_Interface_JsonUnavailable
	{
        static protected $_codeDelimiter = '';
        static protected $_codeDelimiterDebugPostfix = "\r\n";

        public function makeOptions(array $Args=null)
		{
			$options = $Args;
			$argsCount = sizeof($Args);
			if($argsCount == 1 && is_array($Args[0]))
			{
				$options = $Args[0];
			}
			return $options;
		}

		protected function getCodeDelimiter()
		{			$className = get_class($this);
			
			$codeDelimiter = '';
			eval('$codeDelimiter='.$className.'::$_codeDelimiter;');
			
			$postfix = '';
			eval('$postfix='.$className.'::$_codeDelimiterDebugPostfix;');
			
			if($this->isDebug())
			{
				$codeDelimiter .= $postfix;
			}
			return $codeDelimiter;
		}

        public function _toString()
		{
			$parts = (array) $this->_prepareValues();
			$codeDelimiter = $this->getCodeDelimiter();
			$code = "";
			foreach($parts as $part)
			{
				//$code .= ($code ? $codeDelimiter : '').$this->jsonEncode($part);
				$code .= ($code ? $codeDelimiter : '').$part;
			}
			return $code;
		}
		
		protected function _arrayToCodeContainer(array $args = array())
		{
			foreach($args as $n => $arg)
			{
				if(is_array($arg))
				{
					$args[$n] = $this->js()->CodeContainer($arg);
				}
			}
			return $args;			
		}

		public function _append()
		{			$args = func_get_args();
			
			$this->appendSettings($this->_arrayToCodeContainer($args));
			return $this;
		}

		public function _prepend()
		{
			$args = func_get_args();
			$this->prependSettings($this->_arrayToCodeContainer($args));
			return $this;
		}
	}
